#ifndef MYTCPSERVER_H
#define MYTCPSERVER_H

#include <QTcpServer>
#include <QObject>
#include <QMap>


class MyTcpSocket;
class MyTcpServer : public QTcpServer
{
    Q_OBJECT
public:
    explicit MyTcpServer(QObject *parent = nullptr);
protected:
    // 重写这个虚函数，当有新的连接请求时，Qt会自动调用它
    void incomingConnection(qintptr socketDescriptor) override;
public:
    void addOnlineUser(int userId, MyTcpSocket* socket);
    void removeOnlineUser(int userId);
    MyTcpSocket* findOnlineUser(int userId);

public:
    void notifyFriendsOfStatusChange(int userId, const QString& username, const QString& status,const QList<QVariantMap>& friends);
    bool isUserOnline(int id);


private:
    QMap<int, MyTcpSocket*> m_onlineUsers; // 存储在线用户

signals:
};

#endif // MYTCPSERVER_H
